```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Seata 回滚机制深度解析 | 技术小馆</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.6;
        }
        h1, h2, h3, h4, .font-serif {
            font-family: 'Noto Serif SC', serif;
            font-weight: 700;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #6e8efb 0%, #a777e3 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .highlight-text {
            position: relative;
            z-index: 1;
        }
        .highlight-text::after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 0;
            width: 100%;
            height: 30%;
            background-color: rgba(167, 119, 227, 0.2);
            z-index: -1;
            transform: skewY(-1deg);
        }
        .timeline-item::before {
            content: '';
            position: absolute;
            left: -32px;
            top: 0;
            width: 16px;
            height: 16px;
            border-radius: 50%;
            background: #6e8efb;
            border: 3px solid #a777e3;
        }
        .timeline-connector {
            position: absolute;
            left: -25px;
            top: 16px;
            bottom: -16px;
            width: 2px;
            background: #e2e8f0;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-4 md:px-0">
        <div class="container mx-auto max-w-5xl px-4">
            <div class="flex flex-col md:flex-row items-center">
                <div class="md:w-1/2 mb-10 md:mb-0">
                    <h1 class="text-4xl md:text-5xl font-bold mb-6 leading-tight">
                        <span class="highlight-text">Seata 回滚机制</span>深度解析
                    </h1>
                    <p class="text-xl mb-8 opacity-90">
                        揭秘分布式事务如何通过Undo Log实现数据强一致性
                    </p>
                    <div class="flex items-center space-x-4">
                        <span class="bg-white text-purple-700 px-4 py-2 rounded-full text-sm font-semibold">
                            <i class="fas fa-shield-alt mr-2"></i>分布式事务
                        </span>
                        <span class="bg-white text-purple-700 px-4 py-2 rounded-full text-sm font-semibold">
                            <i class="fas fa-database mr-2"></i>数据一致性
                        </span>
                    </div>
                </div>
                <div class="md:w-1/2 flex justify-center">
                    <div class="relative w-64 h-64 md:w-80 md:h-80">
                        <div class="absolute inset-0 bg-white bg-opacity-20 rounded-full animate-pulse"></div>
                        <div class="absolute inset-4 bg-white bg-opacity-10 rounded-full animate-pulse delay-100"></div>
                        <div class="absolute inset-8 bg-white bg-opacity-5 rounded-full animate-pulse delay-200"></div>
                        <div class="absolute inset-0 flex items-center justify-center">
                            <div class="text-center">
                                <i class="fas fa-exchange-alt text-6xl md:text-8xl text-white opacity-90"></i>
                                <p class="mt-4 text-lg font-semibold">分布式事务协调</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <div class="container mx-auto max-w-5xl px-4 py-16">
        <!-- Introduction -->
        <section class="mb-20">
            <div class="bg-white rounded-xl shadow-md p-8 card-hover">
                <p class="text-xl leading-relaxed text-gray-700">
                    Seata 的回滚机制通过全局事务协调、分支事务的 Undo Log 记录、以及可靠的回滚流程，确保了分布式事务在遇到问题时能够正确恢复数据状态。这种机制不仅实现了强一致性，还通过幂等操作和重试策略提高了系统的可靠性和容错能力。
                </p>
            </div>
        </section>

        <!-- Section 1 -->
        <section class="mb-20">
            <h2 class="text-3xl font-bold mb-8 text-gray-800 flex items-center">
                <span class="bg-purple-100 text-purple-700 rounded-full w-10 h-10 flex items-center justify-center mr-4">1</span>
                全局事务的定义与执行
            </h2>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="p-6">
                        <h3 class="text-xl font-semibold mb-4 text-purple-700">
                            <i class="fas fa-fingerprint mr-2"></i>全局事务 ID
                        </h3>
                        <p class="text-gray-700">
                            在事务开始时，Seata 的全局事务协调器（TC）生成一个唯一的全局事务 ID（XID），该 ID 贯穿整个分布式事务的生命周期。
                        </p>
                    </div>
                </div>
                
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="p-6">
                        <h3 class="text-xl font-semibold mb-4 text-purple-700">
                            <i class="fas fa-code-branch mr-2"></i>分支事务的注册
                        </h3>
                        <p class="text-gray-700">
                            每个参与者在执行操作时，会将自己的分支事务注册到 TC 上，表明自己是全局事务的一部分。
                        </p>
                    </div>
                </div>
            </div>
            
            <div class="mt-12">
                <div class="mermaid">
                    graph LR
                    A[客户端] -->|开启事务| B(TC: 生成XID)
                    B --> C[RM1: 分支事务1]
                    B --> D[RM2: 分支事务2]
                    B --> E[RM3: 分支事务3]
                    C -->|注册| B
                    D -->|注册| B
                    E -->|注册| B
                </div>
            </div>
        </section>

        <!-- Section 2 -->
        <section class="mb-20">
            <h2 class="text-3xl font-bold mb-8 text-gray-800 flex items-center">
                <span class="bg-purple-100 text-purple-700 rounded-full w-10 h-10 flex items-center justify-center mr-4">2</span>
                回滚的触发条件
            </h2>
            
            <div class="grid md:grid-cols-3 gap-6">
                <div class="bg-white rounded-xl shadow-md p-6 card-hover border-l-4 border-red-400">
                    <h3 class="text-xl font-semibold mb-3 text-gray-800">
                        <i class="fas fa-exclamation-circle text-red-500 mr-2"></i>分支事务执行失败
                    </h3>
                    <p class="text-gray-700">
                        当一个参与者发现自己的操作无法成功（例如数据库操作失败）时，会主动向 TC 报告失败。
                    </p>
                </div>
                
                <div class="bg-white rounded-xl shadow-md p-6 card-hover border-l-4 border-yellow-400">
                    <h3 class="text-xl font-semibold mb-3 text-gray-800">
                        <i class="fas fa-clock text-yellow-500 mr-2"></i>事务超时
                    </h3>
                    <p class="text-gray-700">
                        如果全局事务在设定的时间内没有完成，TC 会主动触发回滚。
                    </p>
                </div>
                
                <div class="bg-white rounded-xl shadow-md p-6 card-hover border-l-4 border-blue-400">
                    <h3 class="text-xl font-semibold mb-3 text-gray-800">
                        <i class="fas fa-hand-paper text-blue-500 mr-2"></i>手动回滚
                    </h3>
                    <p class="text-gray-700">
                        开发者可以通过代码显式触发事务的回滚。
                    </p>
                </div>
            </div>
        </section>

        <!-- Section 3 -->
        <section class="mb-20">
            <h2 class="text-3xl font-bold mb-8 text-gray-800 flex items-center">
                <span class="bg-purple-100 text-purple-700 rounded-full w-10 h-10 flex items-center justify-center mr-4">3</span>
                Seata 的回滚机制
            </h2>
            
            <div class="mb-12">
                <h3 class="text-2xl font-semibold mb-6 text-gray-800">
                    <i class="fas fa-history text-purple-600 mr-2"></i>Undo Log 的记录
                </h3>
                
                <div class="grid md:grid-cols-2 gap-8">
                    <div>
                        <p class="text-gray-700 mb-6">
                            在每个分支事务执行前，Seata 会自动记录操作的"前镜像"和"后镜像"数据：
                        </p>
                        
                        <ul class="space-y-4">
                            <li class="flex items-start">
                                <span class="bg-purple-100 text-purple-700 rounded-full w-6 h-6 flex items-center justify-center mr-3 flex-shrink-0">
                                    <i class="fas fa-database text-xs"></i>
                                </span>
                                <span class="text-gray-700">
                                    <strong>前镜像</strong>：操作前的数据状态
                                </span>
                            </li>
                            <li class="flex items-start">
                                <span class="bg-purple-100 text-purple-700 rounded-full w-6 h-6 flex items-center justify-center mr-3 flex-shrink-0">
                                    <i class="fas fa-database text-xs"></i>
                                </span>
                                <span class="text-gray-700">
                                    <strong>后镜像</strong>：操作后的数据状态
                                </span>
                            </li>
                        </ul>
                        
                        <p class="text-gray-700 mt-6">
                            这个过程通过 Seata 的 DataSource Proxy 代理来实现。这个代理会拦截 SQL 语句，在操作前后记录数据快照。
                        </p>
                    </div>
                    
                    <div class="bg-white rounded-xl shadow-md p-6 flex items-center justify-center">
                        <div class="mermaid">
                            sequenceDiagram
                            participant C as Client
                            participant RM as Resource Manager
                            participant DB as Database
                            C->>RM: 执行SQL操作
                            RM->>DB: 记录前镜像
                            DB-->>RM: 确认
                            RM->>DB: 执行SQL
                            DB-->>RM: 执行结果
                            RM->>DB: 记录后镜像
                            DB-->>RM: 确认
                        </div>
                    </div>
                </div>
            </div>
            
            <div>
                <h3 class="text-2xl font-semibold mb-6 text-gray-800">
                    <i class="fas fa-undo text-purple-600 mr-2"></i>回滚过程
                </h3>
                
                <div class="relative pl-10">
                    <!-- Timeline Item 1 -->
                    <div class="mb-12 relative timeline-item">
                        <div class="absolute left-0 timeline-connector"></div>
                        <div class="bg-white rounded-xl shadow-md p-6 card-hover">
                            <h4 class="text-xl font-semibold mb-3 text-purple-700">
                                回滚请求的发送
                            </h4>
                            <p class="text-gray-700">
                                当 TC 判断全局事务需要回滚时，会向所有参与的分支事务发送回滚请求。
                            </p>
                        </div>
                    </div>
                    
                    <!-- Timeline Item 2 -->
                    <div class="mb-12 relative timeline-item">
                        <div class="absolute left-0 timeline-connector"></div>
                        <div class="bg-white rounded-xl shadow-md p-6 card-hover">
                            <h4 class="text-xl font-semibold mb-3 text-purple-700">
                                数据恢复
                            </h4>
                            <p class="text-gray-700">
                                每个分支事务收到回滚请求后，通过 Undo Log 中的"前镜像"数据，将数据库状态恢复到操作前的状态。
                            </p>
                        </div>
                    </div>
                    
                    <!-- Timeline Item 3 -->
                    <div class="mb-12 relative timeline-item">
                        <div class="absolute left-0 timeline-connector"></div>
                        <div class="bg-white rounded-xl shadow-md p-6 card-hover">
                            <h4 class="text-xl font-semibold mb-3 text-purple-700">
                                回滚结果的报告
                            </h4>
                            <p class="text-gray-700">
                                分支事务完成回滚后，将结果（成功或失败）报告给 TC。
                            </p>
                        </div>
                    </div>
                    
                    <!-- Timeline Item 4 -->
                    <div class="relative timeline-item">
                        <div class="bg-white rounded-xl shadow-md p-6 card-hover">
                            <h4 class="text-xl font-semibold mb-3 text-purple-700">
                                全局事务状态更新
                            </h4>
                            <p class="text-gray-700">
                                当所有分支事务都回滚成功时，TC 将该全局事务标记为回滚完成。如果有任何分支事务回滚失败，TC 可能会再次尝试或采取其他补救措施。
                            </p>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Section 4 -->
        <section class="mb-20">
            <h2 class="text-3xl font-bold mb-8 text-gray-800 flex items-center">
                <span class="bg-purple-100 text-purple-700 rounded-full w-10 h-10 flex items-center justify-center mr-4">4</span>
                一致性和可靠性保障
            </h2>
            
            <div class="grid md:grid-cols-3 gap-6">
                <div class="bg-white rounded-xl shadow-md p-8 card-hover transform transition hover:scale-105">
                    <div class="text-purple-600 mb-4">
                        <i class="fas fa-check-double text-3xl"></i>
                    </div>
                    <h3 class="text-xl font-semibold mb-3 text-gray-800">强一致性</h3>
                    <p class="text-gray-700">
                        通过 Undo Log 的使用，Seata 可以在回滚时确保数据的一致性，即使在分布式环境中，所有参与者的数据状态也能保持一致。
                    </p>
                </div>
                
                <div class="bg-white rounded-xl shadow-md p-8 card-hover transform transition hover:scale-105">
                    <div class="text-purple-600 mb-4">
                        <i class="fas fa-redo-alt text-3xl"></i>
                    </div>
                    <h3 class="text-xl font-semibold mb-3 text-gray-800">幂等性</h3>
                    <p class="text-gray-700">
                        Seata 的回滚操作是幂等的，即无论回滚请求被执行多少次，数据最终都会恢复到一致的状态。
                    </p>
                </div>
                
                <div class="bg-white rounded-xl shadow-md p-8 card-hover transform transition hover:scale-105">
                    <div class="text-purple-600 mb-4">
                        <i class="fas fa-shield-alt text-3xl"></i>
                    </div>
                    <h3 class="text-xl font-semibold mb-3 text-gray-800">容错处理</h3>
                    <p class="text-gray-700">
                        Seata 设计了重试机制，确保在网络抖动、服务短暂不可用等情况下，回滚操作能够最终完成。
                    </p>
                </div>
            </div>
        </section>

        <!-- Summary -->
        <section class="bg-gradient-to-r from-purple-50 to-blue-50 rounded-xl p-8 md:p-12 mb-20">
            <div class="flex items-start">
                <div class="bg-purple-100 text-purple-700 rounded-full w-12 h-12 flex items-center justify-center mr-6 flex-shrink-0">
                    <i class="fas fa-lightbulb text-xl"></i>
                </div>
                <div>
                    <h3 class="text-2xl font-bold mb-4 text-purple-800">核心要点总结</h3>
                    <ul class="space-y-3 text-gray-700">
                        <li class="flex items-start">
                            <span class="text-purple-500 mr-2">•</span>
                            <span>全局事务协调器(TC)负责管理XID和分支事务状态</span>
                        </li>
                        <li class="flex items-start">
                            <span class="text-purple-500 mr-2">•</span>
                            <span>Undo Log记录前后镜像数据是实现回滚的关键</span>
                        </li>
                        <li class="flex items-start">
                            <span class="text-purple-500 mr-2">•</span>
                            <span>多种触发条件确保异常情况下数据安全</span>
                        </li>
                        <li class="flex items-start">
                            <span class="text-purple-500 mr-2">•</span>
                            <span>幂等性和重试机制保障系统可靠性</span>
                        </li>
                    </ul>
                </div>
            </div>
        </section>
    </div>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-300 py-12">
        <div class="container mx-auto max-w-5xl px-4">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div class="mb-6 md:mb-0">
                    <h3 class="text-xl font-bold text-white mb-2">技术小馆</h3>
                    <p class="text-gray-400">探索技术的无限可能</p>
                </div>
                <div>
                    <a href="http://www.yuque.com/jtostring" class="text-gray-300 hover:text-white transition duration-300 flex items-center">
                        <i class="fas fa-external-link-alt mr-2"></i>
                        http://www.yuque.com/jtostring
                    </a>
                </div>
            </div>
            <div class="border-t border-gray-800 mt-8 pt-8 text-center text-gray-500 text-sm">
                &copy; 2023 技术小馆. 保留所有权利.
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: false,
                htmlLabels: true,
                curve: 'basis'
            }
        });
    </script>
</body>
</html>
```